/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package medidortemperatura;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

/**
 *
 * @author Saul Calderon
 */
public class Graficador {
     /** El panel que muestra la grafica del voltaje */
    private ChartPanel chartPanel;
    
    
    
    private TimeSeries[] series;
     
     public Graficador(int numSeries){
         this.series = new TimeSeries[ numSeries ];         
     }
     
     public void crearSerie(int num, String nombreSerie){
        series[num] = new TimeSeries(nombreSerie, Millisecond.class);        
     }
    
    public ChartPanel crearGrafica(String titulo, String ejeY, String ejeX){
         
         TimeSeriesCollection dataset = new TimeSeriesCollection();
         for(int i = 0; i < this.series.length; ++i){
             if( this.series[i] != null )
                dataset.addSeries(this.series[ i ]);
         }
        final JFreeChart chart = ChartFactory.createTimeSeriesChart(
            titulo, 
            ejeX, 
            ejeY,
            dataset,             
            true, 
            true, 
            false
        ); 
        final XYPlot plot = chart.getXYPlot();        
        ValueAxis axis = plot.getDomainAxis();        
        axis.setAutoRange(true);                  
        chart.setAntiAlias(true);
        chartPanel = new ChartPanel(chart);         
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        return chartPanel;
    }   
   
    
     public void borrarGraficas(){
         for(int i = 0; i < this.series.length; ++i){
             if(this.series[i] != null )
                 this.series[i].clear();
         }
     }
     
     public void agregarEntrada(int serie, double valor){
         Millisecond ms = new Millisecond();
         this.series[serie].add(ms, valor);
     
     }
    
}
